package pe.gob.foncodes.sega.bs.util;

import java.io.Serializable;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Locale;
import java.util.regex.*;


public class FuncionesValid implements Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public FuncionesValid(){
		
	}
		
	public static boolean validaAlfanumerico(String txt){		
		Pattern p=Pattern.compile("[^A-Za-z.������������@_-~#\\ ]+");
		Matcher m=p.matcher(txt);
		return !m.find();				
	}
	
	public static boolean esFechaValida(String fechax) {
		
		  try {
		      SimpleDateFormat formatoFecha = new SimpleDateFormat("dd/MM/yyyy", Locale.getDefault());
		      formatoFecha.setLenient(false);
		      formatoFecha.parse(fechax);
		  } catch (ParseException e) {
		      return false;
		  }
		  return true;
		}

	public static boolean esFormatoFechaValida(String fechax){
		return fechax.matches("\\d{1,2}/\\d{1,2}/\\d{1,4}");
	}
	
	public static boolean esNumExpJudicialValido(String numExp){									
		//Pattern p=Pattern.compile("\\d{5}-\\d{4}-\\d{1,3}-\\w{4}-\\w{2}-\\w{2}-\\d{2}");
		//Pattern p=Pattern.compile("d{5}-d{4}-d{1,3}-w{4}-w{2}-w{2}-d{2}");
		//Matcher m=p.matcher(numExp);
		return numExp.matches("\\d{5}-\\d{4}-\\d{1,3}-\\w{4}-\\w{2}-\\w{2}-\\d{2}");					
	}
	public static boolean esNumResolDeudaValido(String numResol){		
		Matcher mt=null;
		Pattern pt=null;
		boolean esValido=false;
		numResol=numResol.replaceAll("\\.","");
		numResol=numResol.replaceAll("Nro"," ");
		numResol=numResol.replaceAll("N�"," ");
		numResol=numResol.replaceAll("N�"," ");
		numResol=numResol.replaceAll("#","");
		numResol=numResol.replaceAll("NUM","");
		numResol=numResol.replaceAll("RER","RER ");
		numResol=numResol.replaceAll("RM","RM ");
		numResol=numResol.replaceAll("\\ +"," ");				 
		//System.out.print("::"+numResol+"::");
		pt=Pattern.compile("(RER|RM)\\ \\d+-\\d{4,4}[^0-9]{4,6}");		
		mt=pt.matcher(numResol);		 
		esValido=mt.find();
		if(esValido)
		esValido=!mt.find();
		System.out.println("esValido:"+esValido);
		if(esValido)
		esValido=!(numResol.split("RER").length>2||numResol.split("RM").length>2);
				
		System.out.println("esValido:"+esValido);
		
		
		return esValido;
	}
	
	
	
}
